/**
 * @file useLed.c
 * @brief   
 * @author  xiaowine (xiaowine@sina.cn)
 * @version 01.00
 * @date    2021-04-10
 * 
 * @copyright Copyright (c) {2020}  xiaowine
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2021-04-10 <td>1.0     <td>wangh     <td>内容
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        女神助攻,流量冲天
 * *            ..::::::::::::.     永不宕机,代码无bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */

/* Private includes ----------------------------------------------------------*/
#include "userLed.h"
#include "cmsis_os.h"
#include "stm32f0xx_hal.h"
#include "user_data.h"
#include <string.h>
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

Color_st RGBState[3] = {0};
Color_st RGBRec[3] = {0};
Color_st showRGBRec[3] = {0};
/********************************************************************/
#define LEDNUM 4
unsigned char levelLedState = 0;
unsigned char ledFlashFast[LEDNUM] = {0};

volatile _USR_FLAGA_type ledState[2];
#define led00State ledState[0].s4bits.s0
#define led01State ledState[0].s4bits.s1
#define led02State ledState[1].s4bits.s0
#define led03State ledState[1].s4bits.s1

#define waterSrcLedState led00State
#define waterOutLedState led01State
#define heaterLedState led02State
#define waterLevelLedState led03State
unsigned int ledValue = 0;
/* Private function prototypes -----------------------------------------------*/
static void ledSetState(unsigned char num, ledState_t state);
/* Private user code ---------------------------------------------------------*/

/**
 * @brief   
 */
void rgbInit(void)
{
    memset(RGBState, 0, sizeof(RGBState));
}
/**
 * @brief   
 */
void userRGB(void)
{
    // while (1)
    // {
    //     Color_st colorCache;
    //     colorCache = RGBState[0];
    //     RGBState[0] = RGBState[1];
    //     RGBState[1] = RGBState[2];
    //     RGBState[2] = colorCache;
    //     osDelay(1000);
    //     memset(&RGBState[0], 0, 9);
    //     __disable_irq();
    //     ws2812WriteColor(RGBState[0]);
    //     ws2812WriteColor(RGBState[1]);
    //     ws2812WriteColor(RGBState[2]);
    //     __enable_irq();
    // }

    if (rgbNeedRefresh)
    {
        rgbNeedRefresh = 0;
        memcpy(&showRGBRec[0], &RGBState[0], 9);
        __disable_irq();
        ws2812WriteColor(showRGBRec[0]);
        ws2812WriteColor(showRGBRec[1]);
        ws2812WriteColor(showRGBRec[2]);
        __enable_irq();
    }
}
/**
 * @brief   
 * @param  color            My Param doc
 */
void ws2812WriteColor(Color_st color)
{
    ws2812WriteByte(color.green);
    ws2812WriteByte(color.red);
    ws2812WriteByte(color.blue);
}
/**
 * @brief   
 * @param  dat              My Param doc
 */
void ws2812WriteByte(unsigned char dat)
{
    unsigned char i = 8;
    for (i = 0; i < 8; i++)
    {
        // if ((dat & 0x80) > 0)
        // {
        //     GPIO_SetBits(GPIOF, GPIO_PIN_0);
        //     __nop();
        //     GPIO_ResetBits(GPIOF, GPIO_PIN_0);
        // }
        // else
        // {
        //     GPIO_SetBits(GPIOF, GPIO_PIN_0);
        //     GPIO_ResetBits(GPIOF, GPIO_PIN_0);
        // }

        /**
         * @brief   SystemCoreClock=48MHz
         */

        if ((dat & 0x80) > 0)
        {
            GPIOA->BSRR = GPIO_PIN_4;
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            GPIOA->BRR = GPIO_PIN_4;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_4;
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            __nop();
            GPIOA->BRR = GPIO_PIN_4;
        }
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();

        dat <<= 1;
    }
}

/**
 * @brief   
 */
void ledInit(void)
{
    do
    {
        unsigned char i;
        i++;
        if (i <= 20)
        {
            levelSetState(i);
        }
        else if (i <= 40)
        {
            levelSetState(40 - i);
        }
        else
        {
            break;
        }
        osDelay(63);
    } while (1);
}
void userLed(void)
{
    if (FLAG_250MSF)
    {
        if (flashFlag_2HZ)
        {
            flashFlag_2HZ = 0;
        }
        else
        {
            flashFlag_2HZ = 1;
        }
    }
    if (FLAG_500MSF)
    {
        // RUN = !RUN;
        if (flashFlag_1HZ)
        {
            flashFlag_1HZ = 0;
        }
        else
        {
            flashFlag_1HZ = 1;
        }
        if (flashFlag_1HZ)
        {
            if (flashFlag_0_5HZ)
            {
                flashFlag_0_5HZ = 0;
            }
            else
            {
                flashFlag_0_5HZ = 1;
            }
        }
        levelSetState(levelLedState);
    }

    /***************************/
    if (FLAG_63MSF || FLAG_250MSF || FLAG_500MSF)
    {
        unsigned char i, value, State;
        unsigned int ledValueTemp = ledValue;
        for (i = 0; i < LEDNUM; i++)
        {
            value = ((ledValueTemp >> i) & 1);
            if (i % 2 == 0)
            {
                State = ledState[i / 2].byte & 0x0f;
            }
            else
            {
                State = (ledState[i / 2].byte >> 4);
            }

            if (ledFlashFast[i] > 0)
            {
                if (State >= STATE_LED_FLASH_1_T)
                {
                    ledFlashFast[i] += 2 * (State - STATE_LED_FLASH_0_5HZ);
                    if (i % 2 == 0)
                    {
                        ledState[i / 2].byte &= 0xf0;
                    }
                    else
                    {
                        ledState[i / 2].byte &= 0x0f;
                    }
                }
                if (FLAG_63MSF)
                {
                    ledFlashFast[i]--;
                    value = !((ledValueTemp >> i) & 1);
                }
            }
            else
            {
                switch (State)
                {
                case STATE_LED_OFF:
                    value = LED_OFF;
                    break;
                case STATE_LED_ON:
                    value = LED_ON;
                    break;
                case STATE_LED_FLASH_2HZ:
                    if (FLAG_250MSF)
                        value = flashFlag_2HZ;
                    break;
                case STATE_LED_FLASH_1HZ:
                    if (FLAG_500MSF)
                        value = flashFlag_1HZ;
                    break;
                case STATE_LED_FLASH_0_5HZ:
                    if (FLAG_500MSF)
                        value = flashFlag_0_5HZ;
                    break;
                case STATE_LED_FLASH_1_T: //闪烁一下
                case STATE_LED_FLASH_2_T: //闪烁两下
                case STATE_LED_FLASH_3_T: //闪烁三下
                    ledFlashFast[i] += 2 * (State - STATE_LED_FLASH_0_5HZ);
                    if (i % 2 == 0)
                    {
                        ledState[i / 2].byte &= 0xf0;
                    }
                    else
                    {
                        ledState[i / 2].byte &= 0x0f;
                    }
                    break;
                }
            }
            if (value)
            {
                ledValueTemp |= 1 << i;
            }
            else
            {
                ledValueTemp &= ~(1 << i);
            }
            if (ledValueTemp ^ ledValue)
            {
                if (ledValueTemp & (1 << i))
                {
                    ledSetState(i, LED_OFF);
                }
                else
                {
                    ledSetState(i, LED_ON);
                }
            }
            ledValue = ledValueTemp;
        }
    }
}
/**
 * @brief
 * @param  num              My Param doc
 * @param  state            My Param doc
 */
static void ledSetState(unsigned char num, ledState_t state)
{
    switch (num)
    {
    case LEDNUM00:
        if (state == LEDON)
        {
            memcpy(&RGBState[0], &RGBRec[0], 3);
        }
        else
        {
            memset(&RGBState[0], 0, 3);
        }
        rgbNeedRefresh = 1;
        break;
    case LEDNUM01:
        if (state == LEDON)
        {
            memcpy(&RGBState[1], &RGBRec[1], 3);
        }
        else
        {
            memset(&RGBState[1], 0, 3);
        }
        rgbNeedRefresh = 1;
        break;
    case LEDNUM02:
        if (state == LEDON)
        {
            memcpy(&RGBState[2], &RGBRec[2], 3);
        }
        else
        {
            memset(&RGBState[2], 0, 3);
        }
        rgbNeedRefresh = 1;
        break;
    case LEDNUM03:
        levelFlash(levelLedState, state);
        break;
    default:
        break;
    }
}

/**                     NO                        OFF    
 * LED00     PA6 GPIOA->BRR = GPIO_PIN_6;  GPIOA->BSRR = GPIO_PIN_6;
 * LED01     PA5 GPIOA->BRR = GPIO_PIN_5;  GPIOA->BSRR = GPIO_PIN_5;
 * LED02     PA3 GPIOA->BRR = GPIO_PIN_3;  GPIOA->BSRR = GPIO_PIN_3;
 * LED03     PA2 GPIOA->BRR = GPIO_PIN_2;  GPIOA->BSRR = GPIO_PIN_2;
 * LED04     PA1 GPIOA->BRR = GPIO_PIN_1;  GPIOA->BSRR = GPIO_PIN_1;
 * LED05     PA0 GPIOA->BRR = GPIO_PIN_0;  GPIOA->BSRR = GPIO_PIN_0;
 * LED06     PF1 GPIOF->BRR = GPIO_PIN_1;  GPIOF->BSRR = GPIO_PIN_1;
 * LED07     PF0 GPIOF->BRR = GPIO_PIN_0;  GPIOF->BSRR = GPIO_PIN_0;
 * LED08     PC15 GPIOC->BRR = GPIO_PIN_15;  GPIOC->BSRR = GPIO_PIN_15;
 * LED09    PC14 GPIOC->BRR = GPIO_PIN_14;  GPIOC->BSRR = GPIO_PIN_14;
 * LED10    PC13 GPIOC->BRR = GPIO_PIN_13;  GPIOC->BSRR = GPIO_PIN_13;
 * LED11    PA7 GPIOA->BRR = GPIO_PIN_7;  GPIOA->BSRR = GPIO_PIN_7;
 * LED12    PB0 GPIOB->BRR = GPIO_PIN_0;  GPIOB->BSRR = GPIO_PIN_0;
 * LED13    PB1 GPIOB->BRR = GPIO_PIN_1;  GPIOB->BSRR = GPIO_PIN_1;
 * LED14    PB10 GPIOB->BRR = GPIO_PIN_10;  GPIOB->BSRR = GPIO_PIN_10;
 * LED15    PB11 GPIOB->BRR = GPIO_PIN_11;  GPIOB->BSRR = GPIO_PIN_11;
 * LED16    PB12 GPIOB->BRR = GPIO_PIN_12;  GPIOB->BSRR = GPIO_PIN_12;
 * LED17    PB13 GPIOB->BRR = GPIO_PIN_13;  GPIOB->BSRR = GPIO_PIN_13;
 * LED18    PB15 GPIOB->BRR = GPIO_PIN_15;  GPIOB->BSRR = GPIO_PIN_15;
 * LED19    PB14 GPIOB->BRR = GPIO_PIN_14;  GPIOB->BSRR = GPIO_PIN_14;
 * ***********************************************/

/**
 * @brief
 * @param  level            My Param doc
 */
static void levelSetState(unsigned char level)
{
    switch (level)
    {
    case 0:
        GPIOA->BSRR = GPIO_PIN_5;  // LED01 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_3;  // LED02 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_2;  // LED03 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_1;  // LED04 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_0;  // LED05 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 1:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BSRR = GPIO_PIN_3;  // LED02 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_2;  // LED03 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_1;  // LED04 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_0;  // LED05 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 2:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BSRR = GPIO_PIN_2;  // LED03 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_1;  // LED04 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_0;  // LED05 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 3:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BSRR = GPIO_PIN_1;  // LED04 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_0;  // LED05 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 4:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BSRR = GPIO_PIN_0;  // LED05 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 5:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOF->BSRR = GPIO_PIN_1;  // LED06 = LEDOFF;
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 6:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BSRR = GPIO_PIN_0;  // LED07 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 7:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOC->BSRR = GPIO_PIN_15; // LED08 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 8:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BSRR = GPIO_PIN_14; // LED09 = LEDOFF;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 9:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BSRR = GPIO_PIN_13; // LED10 = LEDOFF;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 10:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOA->BSRR = GPIO_PIN_7;  // LED11 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 11:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOB->BSRR = GPIO_PIN_0;  // LED12 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 12:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BSRR = GPIO_PIN_1;  // LED13 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 13:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BSRR = GPIO_PIN_10; // LED14 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 14:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;   // LED13 = LEDON;
        GPIOB->BSRR = GPIO_PIN_11; // LED15 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 15:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;   // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10;  // LED14 = LEDON;
        GPIOB->BSRR = GPIO_PIN_12; // LED16 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 16:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;   // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10;  // LED14 = LEDON;
        GPIOB->BRR = GPIO_PIN_11;  // LED15 = LEDON;
        GPIOB->BSRR = GPIO_PIN_13; // LED17 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 17:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;   // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10;  // LED14 = LEDON;
        GPIOB->BRR = GPIO_PIN_11;  // LED15 = LEDON;
        GPIOB->BRR = GPIO_PIN_12;  // LED16 = LEDON;
        GPIOB->BSRR = GPIO_PIN_15; // LED18 = LEDOFF;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 18:
        GPIOA->BRR = GPIO_PIN_6;   //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;   //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;   //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;   //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;   //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;   //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;   //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;   // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15;  // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14;  // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13;  // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;   // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;   // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;   // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10;  // LED14 = LEDON;
        GPIOB->BRR = GPIO_PIN_11;  // LED15 = LEDON;
        GPIOB->BRR = GPIO_PIN_12;  // LED16 = LEDON;
        GPIOB->BRR = GPIO_PIN_13;  // LED17 = LEDON;
        GPIOB->BSRR = GPIO_PIN_14; // LED19 = LEDOFF;
        break;
    case 19:
        GPIOA->BRR = GPIO_PIN_6;  //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;  //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;  //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;  //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;  //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;  //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;  //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;  // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15; // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14; // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13; // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;  // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;  // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;  // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10; // LED14 = LEDON;
        GPIOB->BRR = GPIO_PIN_11; // LED15 = LEDON;
        GPIOB->BRR = GPIO_PIN_12; // LED16 = LEDON;
        GPIOB->BRR = GPIO_PIN_13; // LED17 = LEDON;
        GPIOB->BRR = GPIO_PIN_15; // LED18 = LEDON;
        break;
    case 20:
        GPIOA->BRR = GPIO_PIN_6;  //LED00 PA6
        GPIOA->BRR = GPIO_PIN_5;  //LED01 PA5
        GPIOA->BRR = GPIO_PIN_3;  //LED02 PA3
        GPIOA->BRR = GPIO_PIN_2;  //LED03 PA2
        GPIOA->BRR = GPIO_PIN_1;  //LED04 PA1
        GPIOA->BRR = GPIO_PIN_0;  //LED05 PA0
        GPIOF->BRR = GPIO_PIN_1;  //LED06 PF1
        GPIOF->BRR = GPIO_PIN_0;  // LED07 = LEDON;
        GPIOC->BRR = GPIO_PIN_15; // LED08 = LEDON;
        GPIOC->BRR = GPIO_PIN_14; // LED09 = LEDON;
        GPIOC->BRR = GPIO_PIN_13; // LED10 = LEDON;
        GPIOA->BRR = GPIO_PIN_7;  // LED11 = LEDON;
        GPIOB->BRR = GPIO_PIN_0;  // LED12 = LEDON;
        GPIOB->BRR = GPIO_PIN_1;  // LED13 = LEDON;
        GPIOB->BRR = GPIO_PIN_10; // LED14 = LEDON;
        GPIOB->BRR = GPIO_PIN_11; // LED15 = LEDON;
        GPIOB->BRR = GPIO_PIN_12; // LED16 = LEDON;
        GPIOB->BRR = GPIO_PIN_13; // LED17 = LEDON;
        GPIOB->BRR = GPIO_PIN_15; // LED18 = LEDON;
        GPIOB->BRR = GPIO_PIN_14; // LED19 = LEDON;
        break;
    default:
        break;
    }
}

/**
 * @brief
 * @param  level            My Param doc
 * @param  state            My Param doc
 */
void levelFlash(unsigned char level, ledState_t state)
{
    switch (level)
    {
    case 0:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_6;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_6;
        }
        break;
    case 1:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_5;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_5;
        }
        break;
    case 2:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_3;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_3;
        }
        break;
    case 3:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_2;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_2;
        }
        break;
    case 4:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_1;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_1;
        }
        break;
    case 5:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_0;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_0;
        }
        break;
    case 6:
        if (state == LEDON)
        {
            GPIOF->BRR = GPIO_PIN_1;
        }
        else
        {
            GPIOF->BSRR = GPIO_PIN_1;
        }
        break;
    case 7:
        if (state == LEDON)
        {
            GPIOF->BRR = GPIO_PIN_0;
        }
        else
        {
            GPIOF->BSRR = GPIO_PIN_0;
        }
        break;
    case 8:
        if (state == LEDON)
        {
            GPIOC->BRR = GPIO_PIN_15;
        }
        else
        {
            GPIOC->BSRR = GPIO_PIN_15;
        }
        break;
    case 9:
        if (state == LEDON)
        {
            GPIOC->BRR = GPIO_PIN_14;
        }
        else
        {
            GPIOC->BSRR = GPIO_PIN_14;
        }
        break;
    case 10:
        if (state == LEDON)
        {
            GPIOC->BRR = GPIO_PIN_13;
        }
        else
        {
            GPIOC->BSRR = GPIO_PIN_13;
        }
        break;
    case 11:
        if (state == LEDON)
        {
            GPIOA->BRR = GPIO_PIN_7;
        }
        else
        {
            GPIOA->BSRR = GPIO_PIN_7;
        }
        break;
    case 12:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_0;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_0;
        }
        break;
    case 13:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_1;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_1;
        }
        break;
    case 14:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_10;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_10;
        }
        break;
    case 15:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_11;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_11;
        }
        break;
    case 16:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_12;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_12;
        }
        break;
    case 17:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_13;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_13;
        }
        break;
    case 18:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_15;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_15;
        }
        break;
    case 19:
        if (state == LEDON)
        {
            GPIOB->BRR = GPIO_PIN_14;
        }
        else
        {
            GPIOB->BSRR = GPIO_PIN_14;
        }
        break;
    default:
        break;
    }
}
